package a.面试;

import org.junit.Test;

public class xiaomi {

    @Test
    public void test() {
        int[] p = {1,2};
        System.out.println(findPeakElement(p));
    }

    public int findPeakElement(int[] nums) {
        int n=nums.length;
        int l=0,r=n-1;
        while(l<r){
            int m=l+r>>1;
            //
            if(m==0 && nums[0]>nums[1])return 0;
            if(m==n-1 && nums[n-2]<nums[n-1])return n-1;

            if(m-1>0&&m+1<n && nums[m-1]<nums[m]&&nums[m]>nums[m+1])return m;
            //
            if(nums[m]>=nums[m+1])r=m;
            else l=m+1;
        }
        return 0;
    }

}
